#!/bin/bash

#当前目录下进行比较
directory=$PWD
threshold=$1
file_list=$(find "$directory" -type f)

#通过循环进行比较
for file1 in $file_list
do
  for file2 in $file_list
  do

    if [ "$file1" != "$file2" ]; then
      diff_output=$(diff "$file1" "$file2" | grep "^<" | wc -l)
      diff_lines=$((diff_output))
      if [ $diff_lines -lt $threshold ]; then
	  file1_lines=$(wc -l < "$file1")
          file2_lines=$(wc -l < "$file2")
	  echo "$file1 $file2 $diff_lines $file1_lines $file2_lines"
	  output="$file1 $file2 $diff_lines $file1_lines $file2_lines"
	  #将输出追加到output.txt中
	  echo $output >> output.txt
      fi
    fi
  done
done
